home *** CD-ROM | disk | FTP | other *** search
- Path: news.clark.net!not-for-mail
- From: gusty@clark.net (Harlan Messinger)
- Newsgroups: comp.lang.c++
- Subject: Re: Q:order of evaluation
- Date: 20 Jan 1996 00:20:08 GMT
- Organization: Clark Internet Services, Inc., Ellicott City, MD USA
- Message-ID: <4dpcfo$293@clarknet.clark.net>
- References: <4dfhlu$a33$1@mhafn.production.compuserve.com> <hamilton-1801962045570001@dialup-147.austin.io.com>
- NNTP-Posting-Host: explorer.clark.net
- Mime-Version: 1.0
- Content-Type: TEXT/PLAIN; charset=ISO-8859-1
- Content-Transfer-Encoding: 8bit
- X-Newsreader: TIN [UNIX 1.3 950726BETA PL0]
-
- Jim Hamilton (hamilton@shokwave.com) wrote:
- : In article <4dfhlu$a33$1@mhafn.production.compuserve.com>, Holger Maier
- : <100336.3326@CompuServe.COM> wrote:
- :
- : >Consider
- : >#include <iostream>
- : >int main() {
- : > int i=1;int j=i+(i+=1);
- : > cout<<i<<','<<j<<'\n';
- : > return 0;
- : >}
- : >on my compiler this produces 2,4
- : >Looked up the ARM:
- : >5: .. The order of evaluation of subexpressions is determined by the
- : >precedence and grouping of operators.
- : >5.7: The additive operators + and - group left to right.
- : >So, j should be assigned 3 ??
- : >Now the question to you C++ gurus out there on the nets:
- : >Is it really a compiler bug or is it just me misinterpreting the
- : >ARM?
- : >BTW: I know we should not code like that...
- : >Holger
- :
- : The highest precedence in any expression is the insides of parentheses
- : (). Therefore (i+=1) is evaluated before i+().
-
- True, but that's not actually the problem here. The problem is whether
- (i+=1) gets evaluated before the i to the left of the plus sign.
-